require(['jquery', 'slidePlayer', 'layer'], function($, slidePlayer, layer, ) {

    layer.config({
        path: 'https://cdn.bootcss.com/layer/3.1.0/' //layer.js所在的目录，可以是绝对目录，也可以是相对目录
    });

    (function() {
        var slideItem = function() {
            var _that = this;
            _that.config = {};

            /**
             * 存放查看过的用户信息，获取到的不会再次获取
             * params format:{uid:userInfo}
             * example: 
             * {
             * 		1111:{
             * 		    name:'xxx',
             * 		    avatar:'https://avatar.slideloop.com/default.jpg',
             * 		    userPage:'https://slideloop.com/u/1111'
             * 		},
             * }
             */
            _that.userInfoList = {};
            _that.init.apply(_that, arguments);
        }

        slideItem.prototype = {
            init: function() {
                var _that = this;
                _that.bindEvent();
            },

            bindEvent: function() {
                var _that = this;
                _that.initPlayer();
                _that.comment();
                _that.download();
            },

            collectNodes: function() {

            },

            render: function() {

            },
            /**
             * 初始化slidePlayer
             */
            initPlayer() {
                var _that = this;
                new slidePlayer();
            },

            likeAction: function() {

            },

            collectAction: function() {

            },

            getComments: function(page) {
                var _that = this;
                $.ajax({
                    url: CONFIG.commentURL,
                    data: {
                        page: page
                    },
                    success: function(data) {

                    },
                    error: function() {

                    }
                });
            },

            comment: function() {
                var _that = this;
                $('#J-comment').on('click', function(event) {
                    event.preventDefault()
                    if (!CONFIG.isLogin) {
                        _that.unloginBox();
                    }
                    //阻止默认为submit类型按钮导致的表单提交
                    return false;
                });
            },

            download: function() {
                var _that = this;
                $('#J-download').on('click', function(event) {
                    if (!CONFIG.isLogin) {
                        _that.unloginBox();
                    }

                });
            },
            /**
             * @method loginBox登录注册弹窗
             */
            loginBox: function() {
                var _that = this;
                if (!CONFIG.isLogin) {
                    layer.open({
                        type: 1,
                        closeBtn: 0, //不显示关闭按钮
                        anim: 2,
                        shadeClose: true, //开启遮罩关闭
                        content: '内容'
                    });
                }
            },

            unloginBox: function() {
                var _that = this;
                layer.confirm('您尚未登录，请登录后再进行操作！', {
                    title: '提示',
                    btn: ['登录', '取消'], //按钮
                    shadeClose: true,
                }, function(index) {
                    _that.loginBox();
                    layer.close(index);
                });
            },

            getUserInfo: function() {
                var _that = this;
                $.ajax({
                    url: CONFIG.userURL,
                    success: function(data) {
                        //向userInfoList中存储信息
                        //_that.userInfoList[]
                    },
                    error: function() {

                    }
                });
            }
        }

        new slideItem();

    })();


    $(function() {


        $('#J-switchtab').on('click', '.tab-trigger', function() {
            var _index = $(this).index();

            $(this).addClass('switchable')
                .siblings()
                .removeClass('switchable');

            $('#J-switchtab .tab-content')
                .eq(_index)
                .addClass('switchable')
                .siblings()
                .removeClass('switchable');
        });
    });
});